package com.zhiming.item.cotroller;

import com.zhiming.item.pojo.AdvisoryCategory;
import com.zhiming.item.service.AdvisoryCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户咨询板块 Controller
 */

@RestController
public class AdvisoryCategoryController {
    @Autowired
    private AdvisoryCategoryService advisoryCategoryService;

    /**
     * 根据id查询板块
     */
    @GetMapping("/advisoryCategory/{id}")
    public ResponseEntity<AdvisoryCategory> findById(@PathVariable("id") Integer id){
        AdvisoryCategory advisoryCategory =  advisoryCategoryService.findById(id);
        return ResponseEntity.ok(advisoryCategory);
    }

    /**
     * 查询所有板块
     */
    @GetMapping("/advisoryCategory/findAll")
    public ResponseEntity<List<AdvisoryCategory>> findAll(){
        List<AdvisoryCategory> advisoryCategoryList = advisoryCategoryService.findAll();
        return ResponseEntity.ok(advisoryCategoryList);
    }

    /**
     * 新增板块
     */
    @PostMapping("/advisoryCategory")
    public ResponseEntity<Void> saveAdvCategory(AdvisoryCategory advCategoy){
        advisoryCategoryService.saveAdvCategory(advCategoy);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    /**
     * 删除板块
     */
    @DeleteMapping("/advisoryCategory/{id}")
    public ResponseEntity<Void> deleteAdvCategory(@PathVariable("id") Integer id){
        advisoryCategoryService.deleteAdvCategory(id);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }

    /**
     * 修改板块
     */
    @PutMapping("/advisoryCategory")
    public ResponseEntity<Void> updateAdvCategory(AdvisoryCategory advisoryCategory){
        advisoryCategoryService.updateAdvCategory(advisoryCategory);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }
}
